class code3 {
    //每行二分
    public boolean searchMatrix(int[][] matrix, int target) {

        int m = matrix.length;
        if(m == 0) return false;
        int n = matrix[0].length;
        if(n == 0) return false;

        for(int i=0;i<m;i++) {
            int l = 0;
            int r = n-1;
            while(l < r) {
                int mid = l + (r -l + 1)/2 ;
                if(target >= matrix[i][mid]) {
                    l = mid;
                } else {
                    r = mid -1;
                }
            }
            if(target == matrix[i][l]) return true;
        }
        return false;
    }
}